package com.scott.classicthreadmodal.demo2;

import com.scott.classicthreadmodal.demo2.consumer.Consumer;
import com.scott.classicthreadmodal.demo2.producer.Producer;
import com.scott.classicthreadmodal.demo2.storage.StorageExecutor;
import com.scott.classicthreadmodal.demo2.storage.delegate.StorageBlockingQueue;
import com.scott.classicthreadmodal.demo2.storage.delegate.StorageSimple;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo2Test {

    public static void main(String[] args) {
        //这不应该用委派模式，应该用工厂模式
//        StorageExecutor storage = new StorageExecutor(new StorageBlockingQueue());
        StorageExecutor storage = new StorageExecutor(new StorageSimple());
        ExecutorService service = Executors.newCachedThreadPool();

        Producer p1 = new Producer("张三", 2, storage);
        Producer p2 = new Producer("李四", 3, storage);

        Consumer c1 = new Consumer("王五", 5, storage);
        Consumer c2 = new Consumer("刘二", 4, storage);


        service.submit(p1);
        service.submit(p2);

        service.submit(c1);
        service.submit(c2);
    }
}
